package com.cz.mes;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 *  更新订单明细
 */
public class UpdateManufactureOrderBusinessState {
    public static void main(String[] args) {
          String dbGroup = "mes-prod-master";

        try {
            /** 业务状态：0->计划；1->计划确认；2->工艺认领；3->下达；4->开工；5->完工；6->结案；7->强制结案;8->驳回 **/
            String billNo = "MOTJ2505260005";
            String business_state = "5";

            String sql = "select id from manufacture_order where status = 1 and bill_no = ?";
            Entity entity = Db.use(dbGroup).queryOne(sql,billNo);
            if(Objects.nonNull(entity)) {
                String mainId = entity.getStr("id");
                String sql2 = "update manufacture_order_detail set business_state = :business_state where main_id = :main_id";

                Map<String, Object> updateParams = new HashMap<>();
                updateParams.put("business_state", business_state);
                updateParams.put("main_id", mainId);
                int result = Db.use(dbGroup).execute(sql2,updateParams);
                System.out.println("更新多少条数据:" + result);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
